package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.*;
import com.project.mapper.IInventoryInfoMapper;
import com.project.mapper.IInventoryMapper;
import com.project.service.IAllGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AllGoodsServiceImpl implements IAllGoodsService {


    @Autowired
    private IInventoryMapper IInventoryMapper;//库存商品表
    @Autowired
    private IInventoryInfoMapper IInventoryInfoMapper;//库存商品明细表


    @Override
    public IPage<InventoryBean> findAllGoodsItem(int pageNO, String commodityName, String type) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if (commodityName != null && commodityName.length() != 0) {
            queryWrapper.like("commodityName", commodityName);
        }
        if (type != null && type.length() != 0) {
            queryWrapper.like("type", type);
        }
        return IInventoryMapper.selectPage(new Page<>(pageNO, 3), queryWrapper);
    }

    @Override
    public IPage<InventoryInfoBean> findGoodsById(int pageNO, String id) {
        QueryWrapper<InventoryInfoBean> qw = new QueryWrapper<>();
        qw.eq("fk_productNum", id);
        return IInventoryInfoMapper.selectPage(new Page<>(pageNO, 3), qw);
    }

    @Override
    public List<InventoryInfoBean> findGoodsColorsById(String id) {
        return IInventoryInfoMapper.findGoodsColorsById(id);
    }

    @Override
    public IPage<InventoryInfoBean> findGoodsByColor(int pageNO, String id, String color) {
        QueryWrapper qw = new QueryWrapper<>();
        qw.eq("fk_productNum", id);
        qw.eq("color", color);
        return IInventoryInfoMapper.selectPage(new Page<>(pageNO, 3), qw);
    }


}

